package com.groupbuying.ordosmarathon.admin.service.impl;

import com.groupbuying.ordosmarathon.admin.dao.FinanceOrderDao;
import com.groupbuying.ordosmarathon.admin.service.MarathonAdminService;
import com.groupbuying.ordosmarathon.connector.CustomerFeign;
import com.groupbuying.ordosmarathon.connector.SysconfigFeign;
import com.groupbuying.ordosmarathon.marathonOrder.MarathonOrderController;
import com.groupbuying.ordosmarathon.util.PageUtils;
import com.groupbuying.ordosmarathon.util.Query;
import com.groupbuying.ordosmarathon.util.apiresult.ApiResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author: WANGNING
 * @Email wyn20140226@aliyun.com
 * @Date: 2019/8/6 14:53
 * @Des 马拉松后台管理
 */
@Service
public class MarathonAdminServiceImpl implements MarathonAdminService {
    private static final Logger logger = LoggerFactory.getLogger(MarathonAdminServiceImpl.class);
    @Autowired
    private CustomerFeign customerFeign;
    @Autowired
    private MarathonOrderController marathonOrder;
    @Autowired
    private FinanceOrderDao financeOrderDao;
    @Autowired
    private SysconfigFeign sysconfigFeign;

    /**
     * 订单支付查询
     */
    @Override
    public PageUtils payList(Map<String, Object> param) {
        String storeName = sysconfigFeign.getStoreName();
        logger.info("MarathonAdminServiceImpl.payList()-----订单支付查询获取游戏门店名称:" + storeName);
        param.put("ysPayId", "");
        param.put("storeName", storeName);
        Query query = new Query(param);
        List<Map<String, String>> storeMoneyFlowList = financeOrderDao.list(query);
        int total = financeOrderDao.count(param);
        PageUtils pageUtils = new PageUtils(storeMoneyFlowList, total);
        return pageUtils;
    }

    /**
     * 首页--注册会员数
     */
    @Override
    public Integer countCustomerForMls() {
        return customerFeign.countCustomerForMls();
    }

    /**
     * 首页--获取各项订单数/金额数
     */
    @Override
    public Map getCountAndTotalPrice() {
        ApiResult apiResult = marathonOrder.getCountAndTotalPrice();
        Map apiResultMap = (Map) apiResult.getResult();

        return apiResultMap;
    }

    /**
     * 首页--获奖
     */
    @Override
    public Map<String, Integer> getPrize() {
        Map<String, Integer> map = this.customerFeign.sumEvenPrize();
        logger.info("MarathonAdminServiceImpl.getPrize----->获取到的获奖统计为：" + map.toString());
        return map;
    }

    /**
     * 首页参数
     */
    @Override
    public Map homePage() {
        Map<String, Object> condMap = new HashMap<>();
        /* 获取注册用户数*/
        Integer countCustomer = countCustomerForMls();
        logger.info("MarathonAdminServiceImpl.homePage()-----首页参数--获取注册用户数:" + countCustomer);
        /*获取各项订单数/金额数*/
        Map getCountAndTotalPriceMap = getCountAndTotalPrice();
        logger.info("MarathonAdminServiceImpl.homePage()-----首页参数--获取各项订单数/金额数:" + getCountAndTotalPriceMap.toString());
        String caihongOrders = (String) getCountAndTotalPriceMap.get("caihongOrders");
        String wawaOrders = (String) getCountAndTotalPriceMap.get("wawaOrders");
        //String caihongPrice = (String) getCountAndTotalPriceMap.get("caihongPrice");
        String totalPrice = (String) getCountAndTotalPriceMap.get("totalPrice");
        String totalCount = (String) getCountAndTotalPriceMap.get("totalCount");
        String counterOrders = (String) getCountAndTotalPriceMap.get("counterOrders");
        /*获取到的获奖统计*/
        Map<String, Integer> getPrizeMap = this.getPrize();
        logger.info("MarathonAdminServiceImpl.homePage()-----首页参数--获取到的获奖统计:" + getPrizeMap.toString());
        condMap.put("market", getPrizeMap.get("market"));
        condMap.put("rock", getPrizeMap.get("rock"));
        condMap.put("doll", getPrizeMap.get("doll"));
        condMap.put("rubbish", getPrizeMap.get("rubbish"));
        condMap.put("countCustomer", countCustomer);
        condMap.put("caihongOrders", caihongOrders);
        condMap.put("wawaOrders", wawaOrders);
        //condMap.put("caihongPrice", caihongPrice);
        condMap.put("totalPrice", totalPrice);
        condMap.put("counterOrders", counterOrders);
        condMap.put("totalCount", totalCount);
        return condMap;
    }

    /**
     * 获取投屏列表---分页
     * type--1
     */
    @Override
    public PageUtils screenList(Map<String, Object> map) {
        /*投屏标识*/
        PageUtils page = this.customerFeign.getList(map);
        return page;
    }

    /**
     * 投屏页面所有信息
     */
    @Override
    public Map screen(Map<String, Object> map) {
        /*获取中奖会员数*/
        Map<String, Integer> condMap = this.getPrize();
        logger.info("MarathonAdminServiceImpl.screen()-----投屏页面所有信息,获取中奖会员数:" + condMap.toString());
        Integer rock = condMap.get("rock");
        /*投屏列表*/
        map.put("pageUtil", screenList(map));
        map.put("winCustomerSum", rock);
        return map;
    }

    /**
     * 大转盘---娃娃机商品中奖总数和单个商品的详情
     */
    @Override
    public Map wawajiPrizeSumAndSinglePrize(Map<String, Object> map) {
        Map wawajiFinish = new HashMap();
        /*大装盘---娃娃机*/
        String wawajiType = "1";
        /*获取娃娃机中奖总数和单个商品中奖详情*/
        /*获取娃娃机---双层保温杯---2*/
        map.put("source", wawajiType);
        map.put("identifi", "2");
        Map cupMap = this.customerFeign.sumPrize(map);
        logger.info("MarathonAdminServiceImpl.wawajiPrizeSumAndSinglePrize()-大装盘-娃娃机-双层保温杯:" + cupMap.toString());
        Integer cup = (Integer) cupMap.get("detaile");
        /*获取娃娃机---笔记本---3*/
        map.put("source", wawajiType);
        map.put("identifi", "3");
        Map noteWorkMap = this.customerFeign.sumPrize(map);
        Integer noteWork = (Integer) noteWorkMap.get("detaile");
        /*获取娃娃机---新款韩版磨砂创意卡通大肚保温真空杯---4*/
        map.put("source", wawajiType);
        map.put("identifi", "4");
        Map glassMap = this.customerFeign.sumPrize(map);
        Integer glass = (Integer) glassMap.get("detaile");
        /*获取娃娃机---毛巾---5*/
        map.put("source", wawajiType);
        map.put("identifi", "5");
        Map towelMap = this.customerFeign.sumPrize(map);
        Integer towel = (Integer) towelMap.get("detaile");
        Integer all = (Integer) towelMap.get("all");
        wawajiFinish.put("cup", cup);
        wawajiFinish.put("noteWork", noteWork);
        wawajiFinish.put("glass", glass);
        wawajiFinish.put("towel", towel);
        wawajiFinish.put("all", all);
        logger.info("MarathonAdminServiceImpl.wawajiPrizeSumAndSinglePrize()-大装盘-娃娃机:" + wawajiFinish.toString());
        return wawajiFinish;
    }

    /**
     * 垃圾分类---商品中奖总数和单个商品的详情
     */
    @Override
    public Map rubbishPrizeSumAndSinglePrize(Map<String, Object> map) {
        Map rubbishFinish = new HashMap();
        /*大装盘---垃圾分类*/
        String rubbishType = "2";
        /*获取垃圾分类中奖总数和单个商品中奖详情*/
        /*获取垃圾分类---手环---1*/
        map.put("source", rubbishType);
        map.put("identifi", "1");
        Map braceletMap = this.customerFeign.sumPrize(map);
        Integer bracelet = (Integer) braceletMap.get("detaile");
        /*获取垃圾分类---艾涵不锈钢双层保温饭盒---2*/
        map.put("source", rubbishType);
        map.put("identifi", "2");
        Map cupMap = this.customerFeign.sumPrize(map);
        Integer cup = (Integer) cupMap.get("detaile");
        /*获取垃圾分类---一叶知秋仿皮质笔记本---3*/
        map.put("source", rubbishType);
        map.put("identifi", "3");
        Map noteWorkMap = this.customerFeign.sumPrize(map);
        Integer noteWork = (Integer) noteWorkMap.get("detaile");
        /*获取垃圾分类---新款韩版磨砂创意卡通大肚保温真空杯---4*/
        map.put("source", rubbishType);
        map.put("identifi", "4");
        Map glassMap = this.customerFeign.sumPrize(map);
        Integer glass = (Integer) glassMap.get("detaile");
        /*获取垃圾分类---优雅素色方格优质毛巾（红格）---5*/
        map.put("source", rubbishType);
        map.put("identifi", "5");
        Map towelMap = this.customerFeign.sumPrize(map);
        Integer towel = (Integer) towelMap.get("detaile");
        /*获取垃圾分类---Miniso纸巾---6*/
        map.put("source", rubbishType);
        map.put("identifi", "6");
        Map towelMinisoMap = this.customerFeign.sumPrize(map);
        Integer towelMiniso = (Integer) towelMinisoMap.get("detaile");
        Integer all = (Integer) towelMinisoMap.get("all");
        rubbishFinish.put("bracelet", bracelet);
        rubbishFinish.put("cup", cup);
        rubbishFinish.put("noteWork", noteWork);
        rubbishFinish.put("glass", glass);
        rubbishFinish.put("towel", towel);
        rubbishFinish.put("towelMiniso", towelMiniso);
        rubbishFinish.put("all", all);
        logger.info("MarathonAdminServiceImpl.rubbishPrizeSumAndSinglePrize()-大装盘-垃圾分类:" + rubbishFinish.toString());
        return rubbishFinish;
    }

    /**
     * 模拟超市---商品中奖总数和单个商品的详情
     */
    @Override
    public Map marketPrizeSumAndSinglePrize(Map<String, Object> map) {
        Map marketFinish = new HashMap();
        /*大装盘---模拟超市*/
        String marketType = "3";
        /*获取模拟超市中奖总数和单个商品中奖详情*/
        /*获取模拟超市---手环---1*/
        map.put("source", marketType);
        map.put("identifi", "1");
        Map braceletMap = this.customerFeign.sumPrize(map);
        Integer bracelet = (Integer) braceletMap.get("detaile");
        /*获取模拟超市---艾涵不锈钢双层保温饭盒---2*/
        map.put("source", marketType);
        map.put("identifi", "2");
        Map cupMap = this.customerFeign.sumPrize(map);
        Integer cup = (Integer) cupMap.get("detaile");
        /*获取模拟超市---笔记本---3*/
        map.put("source", marketType);
        map.put("identifi", "3");
        Map noteWorkMap = this.customerFeign.sumPrize(map);
        Integer noteWork = (Integer) noteWorkMap.get("detaile");
        /*获取模拟超市---新款韩版磨砂创意卡通大肚保温真空杯---4*/
        map.put("source", marketType);
        map.put("identifi", "4");
        Map glassMap = this.customerFeign.sumPrize(map);
        Integer glass = (Integer) glassMap.get("detaile");
        /*获取模拟超市---miniso毛巾---6*/
        map.put("source", marketType);
        map.put("identifi", "6");
        Map towelMinisoMap = this.customerFeign.sumPrize(map);
        Integer towelMiniso = (Integer) towelMinisoMap.get("detaile");
        Integer all = (Integer) towelMinisoMap.get("all");
        marketFinish.put("bracelet", bracelet);
        marketFinish.put("cup", cup);
        marketFinish.put("noteWork", noteWork);
        marketFinish.put("glass", glass);
        marketFinish.put("towelMiniso", towelMiniso);
        marketFinish.put("all", all);
        logger.info("MarathonAdminServiceImpl.marketPrizeSumAndSinglePrize()-大装盘-模拟超市:" + marketFinish.toString());
        return marketFinish;
    }

    /**
     * 获取大转盘列表---娃娃机---1--详情列表
     */
    @Override
    public Map wawajiDetaile(Map<String, Object> map) {
        String source = "1";
        map.put("source", source);
        PageUtils page = this.customerFeign.getList(map);
        Map condMap = wawajiPrizeSumAndSinglePrize(map);
        Integer cup = (Integer) condMap.get("cup");
        Integer noteWork = (Integer) condMap.get("noteWork");
        Integer glass = (Integer) condMap.get("glass");
        Integer towel = (Integer) condMap.get("towel");
        Integer allCount = (Integer) condMap.get("all");
        map.put("cup", cup);
        map.put("noteWork", noteWork);
        map.put("glass", glass);
        map.put("towelMiniso", towel);
        map.put("allCount", allCount);
        map.put("page", page);
        logger.info("MarathonAdminServiceImpl.wawajiDetaile()-获取大转盘列表-娃娃机:" + map.toString());
        return map;
    }

    /**
     * 获取大转盘列表---垃圾分类---2--详情列表
     */
    @Override
    public Map rubbishDetaile(Map<String, Object> map) {
        String source = "2";
        map.put("source", source);
        PageUtils page = customerFeign.getList(map);
        Map condMap = rubbishPrizeSumAndSinglePrize(map);
        Integer bracelet = (Integer) condMap.get("bracelet");
        Integer cup = (Integer) condMap.get("cup");
        Integer noteWork = (Integer) condMap.get("noteWork");
        Integer glass = (Integer) condMap.get("glass");
        Integer towel = (Integer) condMap.get("towel");
        Integer towelMiniso = (Integer) condMap.get("towelMiniso");
        Integer allCount = (Integer) condMap.get("all");
        map.put("bracelet", bracelet);
        map.put("cup", cup);
        map.put("noteWork", noteWork);
        map.put("glass", glass);
        map.put("towel", towel);
        map.put("towelMiniso", towelMiniso);
        map.put("allCount", allCount);
        map.put("page", page);
        logger.info("MarathonAdminServiceImpl.rubbishDetaile()-获取大转盘列表-垃圾分类:" + map.toString());
        return map;
    }

    /**
     * 获取大转盘列表---模拟超市---3---详情列表
     */
    @Override
    public Map marketDetaile(Map<String, Object> map) {
        String source = "3";
        map.put("source", source);
        PageUtils page = customerFeign.getList(map);
        Map condMap = marketPrizeSumAndSinglePrize(map);
        Integer bracelet = (Integer) condMap.get("bracelet");
        Integer noteWork = (Integer) condMap.get("noteWork");
        Integer cup = (Integer) condMap.get("cup");
        Integer glass = (Integer) condMap.get("glass");
        Integer towelMiniso = (Integer) condMap.get("towelMiniso");
        Integer allCount = (Integer) condMap.get("all");
        map.put("bracelet", bracelet);
        map.put("cup", cup);
        map.put("noteWork", noteWork);
        map.put("glass", glass);
        map.put("towelMiniso", towelMiniso);
        map.put("allCount", allCount);
        map.put("page", page);
        logger.info("MarathonAdminServiceImpl.marketDetaile()-获取大转盘列表-模拟超市:" + map.toString());
        return map;
    }


}
